Welcome to Css!

6.04 元素类型转换2

2、转成行级元素:display:inline

3、转成行内块级元素:display:inline-block

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>css</title>

<style type="text/css">

div{display:inline;

background:blue;width:200px;height:60px}

</style>

</head>

<body>

<div>我要好好学习1</div>

<span>我要好好学习2</span>

</body>

</html>

div设置成行级元素,里面的宽高width:200px;height:60px均没有生效,并且div成行级元素后,会和span元素的内容连在一下,不会换行。如下:

改以行内块级元素,宽高可以设置了并且可以和行内元素连在一起:

div{display:inline-block;

background:blue;width:200px;height:60px}